package mo.golden;

import mo.common.ListNode;

import java.util.HashSet;
import java.util.Set;

public class L02_01 {

    public ListNode removeDuplicateNodes(ListNode head) {
        if (head.next == null) {
            return head;
        }
        Set<Integer> set = new HashSet<>();
        set.add(head.val);
        ListNode pre = head;
        while (pre.next != null) {
            ListNode cur = pre.next;
            if (set.contains(cur.val)) {
                pre.next = pre.next.next;
            } else {
                set.add(cur.val);
                pre = pre.next;
            }
        }
        return head;
    }

}
